<?php

use yii\helpers\Html;
?>
<?= Html::beginTag('div', $htmlOptions) ?>

<?= Html::beginTag('div', $containerOptions) ?>
<?php if ($autoUpload): ?>
    <?= Html::a($browseLabel . '<b>' . $uploadLabel . '</b>', 'javascript:;', $browseOptions) ?>
<?php else: ?>
    <?= Html::a($browseLabel, 'javascript:;', $browseOptions) ?>
    <?= Html::a($uploadLabel, 'javascript:;', $uploadOptions) ?>
<?php endif; ?>
<?= Html::endTag('div') ?>

<?php
$data = $model->$attribute;

$html = '';
if (is_array($data)) {
    foreach ($data as $key => $item) {
        $_attribute = $attribute . '[' . $key . ']';
        $path = Html::getAttributeValue($model, $_attribute . '[path]');
        $size = Html::getAttributeValue($model, $_attribute . '[size]');

        $html .= '<li class="plupload_file" id="ppi_' . $key . '">';
        $html .= Html::activeHiddenInput($model, $_attribute . '[id]');
        $html .= Html::activeHiddenInput($model, $_attribute . '[path]', [
            'class' => 'plupload_file_input',
        ]);

        $html .= '<div class="plupload_file_thumb">' . Html::img($attachUrl . $path, [
            'draggable' => false
        ]) . '</div>';
        $html .= '<div class="plupload_file_action"><i class="ionicons ion-trash-a"></i></div>';

        $html .= '<div class="plupload_file_description">' . Html::activeTextarea($model, $_attribute . '[description]', [
            'placeholder' => '可以为图片添加描述内容',
        ]) . '</div>';

        $html .= '<div class="plupload_file_size">' . $size . '</div>';

        $html .= '</li>';
    }
    if ($allow_max_nums && (count($data) > $allow_max_nums)) {
        $containerOptions['style'] = 'display:none;';
    }
}
?>


<?= Html::tag('ul', $html, $previewOptions) ?>

<div id="<?= $errorContainer ?>" class="plupload-console"></div>

<?= Html::endTag('div') ?>